#!/usr/bin/python3
# -*- coding:UTF-8 -*-

import sys
import argparse
from datetime import datetime
import time

import AutoExecUtils


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("--timeformat", default="", help="Time format string")

    args = parser.parse_args()
    timeFormat = args.timeformat
    exitCode = 0

    try:
        timeStr = ""
        if timeFormat != "":
            timeStr = datetime.now().strftime(timeFormat)
        else:
            timeStr = time.time()

        out = {"timeStr": timeStr}
        AutoExecUtils.saveOutput(out)
    except Exception as err:
        exitCode = 2
        print("ERROR: Get time failed, {}".format(err))

    sys.exit(exitCode)
